package com.example.onlinemonitoring.autoRun;

import com.example.onlinemonitoring.model.Appstation;
import com.example.onlinemonitoring.Util.CommPortManager;
import com.example.onlinemonitoring.Util.LanguageManager;
import com.example.onlinemonitoring.model.Appdevice;
import com.example.onlinemonitoring.serviceImpl.AppdeviceServiceImpl;
import com.example.onlinemonitoring.serviceImpl.AppstationServiceImpl;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 这个类的作用是在程序启动时一直运行，来做某些事情
 * 1.监测变压器站的运行健康状况
 */
@Component
public class CheckRunner implements ApplicationRunner {

    @Autowired
    AppdeviceServiceImpl AppdeviceImpl;
    @Autowired
    AppstationServiceImpl appstationserviceimpl;
    @Autowired
    private CheckService checkService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        checkService.runAppHealthCheck();
    }

    @Service("CheckService")
    public class CheckService {
        /**
         * 循环监测变压器站的运行健康状况
         */
        @Async("threadPoolm")
        public void runAppHealthCheck() {
            // 初始化设备实时列表
            // Example example = new Example(Appdevice.class);
            // Example.Criteria criteria = example.createCriteria();
            // List<Appdevice> devicelist;
            // criteria.andEqualTo("communicationmode", 2);
            // Map<Integer, Long> timemap = new HashMap<>();
            // Map<Integer, Boolean> boolmap = new HashMap<>();

            // while (true) {
            // devicelist = AppdeviceImpl.selectByExample(example);
            // try {
            // } catch (Exception e) {
            // e.printStackTrace();
            // }
            // try {
            // Thread.sleep(200);
            // } catch (InterruptedException e) {
            // e.printStackTrace();
            // }
            // }
        }
    }
}
